package com.jdk.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {

    private static final Integer THREAD_NUM = 30;
    private static ExecutorService executorService = new ThreadPoolExecutor(THREAD_NUM, THREAD_NUM,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(1024),new ThreadPoolExecutor.CallerRunsPolicy());

    public static void main(String[] args) {
        String[] type = {"售票","兑奖","注销"};
        for(int i = 0; i<type.length; i++){
            FileThread fileThread = new FileThread(i+"", "computer-tickets", type[i]);
            executorService.execute(fileThread);
        }
    }



}


class FileThread implements Runnable{

    private String date;

    private String mechantId;

    private String businessType;

    public FileThread(String date, String mechantId, String businessType) {
        this.date = date;
        this.mechantId = mechantId;
        this.businessType = businessType;
    }

    @Override
    public void run() {
        //查询数据库
        //根据参数定义文件路径
        //查询数据写入文件
        //文件打包上传
        System.out.println(this.toString());
    }

    @Override
    public String toString() {
        return "FileThread{" +
                "date='" + date + '\'' +
                ", mechantId='" + mechantId + '\'' +
                ", businessType='" + businessType + '\'' +
                '}';
    }
}
